package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
public class SetmealController {

    @Autowired
    SetmealService setmealService;

    //套餐分页查询
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult page= setmealService.page(setmealPageQueryDTO);
        return Result.success(page);
    }

    //套餐新增
    @PostMapping
    public Result save(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐数据：{}",setmealDTO);
        setmealService.save(setmealDTO);
        return Result.success();
    }

    //套餐查询（根据Id）
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.getById(id);
        return Result.success(setmealVO);
    }


    //套餐修改
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐数据：{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }
   //套餐批量删除
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids){
        log.info("批量删除菜品，ids：{}", ids);
        setmealService.delete(ids);
        return Result.success();
    }

    //套餐起售停售
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status, Long id){
        setmealService.permission(status,id);
        return Result.success();
    }



}
